import React, { Component } from 'react';
import {
  Modal,
  Toast,
  Flex,
  Button,
  Checkbox,
  List,
  Icon,
  Stepper,
    WingBlank
} from 'antd-mobile';
import CartGoods from './cartGodds';
import { cart_shop } from './CartShop.less';
const Item = List.Item;
const AgreeItem = Checkbox.AgreeItem;
import CouponItem from './CouponItem';
import CanChangeScroll from "../../components/CanChangeScroll/CanChangeScroll";
import CartStoreActivity from "./cartStoreActivity"
import noCoupon from "../../assets/img/noCoupon.svg";
import rightSvg from "../../assets/img/right.svg";

import { routerRedux } from 'dva/router';

class CartShop extends Component {
  constructor(props) {
    super(props);
    this.state = {
      vsible: false
    };

  }



  // 领券list
  getCoupon = (store) => {
      this.props.dispatch({ type: 'cart/couponlistEFF', obj: { storeId: store.storeId } }).then(() => {
          this.setState({
              vsible: true,
          });
      });
  }



  // componentWillUnmount(){
  //   console.log(1)
  //   this.setState({
  //     vsible:false
  //   })
  // }


  // 更新购物车数量
  updateModelCart = (index, listIndex, num) => {
   this.props.dispatch({ type: 'cart/changeCartNum', index, listIndex, num });
  }


  // 选中店
  checkShop = (e) => {
       const { index, data  } = this.props;
       if (e.target.checked == true) {
         this.props.dispatch({ type: 'cart/checkShopCartEFF',  shopIndex:index, isCheck:1, obj:{ id: data.storeId } });
       } else if (e.target.checked == false) {
         this.props.dispatch({ type: 'cart/checkShopCartEFF',  shopIndex:index, isCheck:0,  obj:{ id: data.storeId } });
       }
  }

  hasStoreCheeck=(ids) => {
      const isCheckEvery = ids.goodslist.every((vv,ii,aa)=>{
          return vv.isCheck==1
      });
      return isCheckEvery;
  }

  storeClick = e => this.props.data.storeId!=0 && this.props.dispatch( routerRedux.push({pathname: `/storesShow/${this.props.data.storeId}`}) )

  renderHeader = () => {
    const { data, couponList } = this.props;
   // console.log(+data.storeId, !!+data.storeId, "cartShop .......................");

    return (
        <Flex>
              <Checkbox checked={ data.storeIsAllCheck==1 ? true : false } onChange={ this.checkShop }/>
              <span className="store_name" onClick={ this.storeClick }>{data.storeName}</span>
              {
                  data.storeId != 0 ?
                  <Icon style={{ color:'#1d1d1d',width:".3rem",height:".3rem" }} type={rightSvg.id} /> : ''
              }
              {/* <Icon style={{ color:'#1d1d1d',width:".5rem",height:".5rem" }} type="right" /> */}
              <Flex.Item style={{ textAlign: 'right' }}>
                {/*<span className='line'></span>*/}
                <div style={{ color:'#ff0036' ,fontSize:'.3rem'}} onClick={() => this.getCoupon(data)}>领券</div>
              </Flex.Item>
        </Flex>
    );
  };



  render() {
    const { vsible } = this.state;
    const { data, select, index, dispatch, editStatus,couponList=[] } = this.props;
    const { goodslist=[], activityPromotionRuleList=[],mansongGiftList=[] } = data;
   // const datanum = data.list || [];
      console.log(activityPromotionRuleList)
      console.log(activityPromotionRuleList!="")
    return (
      <div className={cart_shop}>
        <List  renderHeader={this.renderHeader}>

            <WingBlank>
                {activityPromotionRuleList!=""?<CartStoreActivity contentList={activityPromotionRuleList}/>:""}
                {/*{mansongGiftList!=undefined&&mansongGiftList!=[]?<CartStoreActivity contentList={mansongGiftList}/>:""}*/}
                {/*{*/}
                    {/*activityPromotionRuleList!=undefined&&activityPromotionRuleList!==''&&activityPromotionRuleList.map((v,i,a)=>{*/}
                        {/*let name = "";*/}
                        {/*// let orderType = 1;*/}
                        {/*switch (v.activityType) {*/}
                            {/*case 10:*/}
                                {/*name = '满减';*/}
                                {/*break;*/}
                            {/*case 20:*/}
                                {/*name = "满免邮";*/}
                                {/*break;*/}
                            {/*case 30:*/}
                                {/*name = "满送";*/}
                                {/*break;*/}
                            {/*case 40:*/}
                                {/*name = "满折";*/}
                                {/*break;*/}
                            {/*case 50:*/}
                                {/*name = "团购";*/}
                                {/*break;*/}
                            {/*case 60:*/}
                                {/*name = "限时抢购";*/}
                                {/*break;*/}
                            {/*case 90:*/}
                                {/*name = "优惠券"*/}
                                {/*break;*/}
                        {/*}*/}

                        {/*return (*/}
                            {/*<Flex key={i} style={{margin:".1rem .1rem 0 .6rem"}} className="store_activity">*/}
                                {/*<div*/}
                                    {/*style={{*/}
                                        {/*padding:"0.05rem 0.1rem",*/}
                                        {/*fontSize:"0.2rem",*/}
                                        {/*color:"#ff0036",*/}
                                        {/*backgroundColor:'#fbe9e9',*/}
                                        {/*marginRight:'0.1rem'*/}
                                    {/*}}>*/}
                                    {/*{name}*/}
                                {/*</div>*/}
                                {/*<div style={{ fontSize:"0.22rem", color:"#333" }}>{v.name}</div>*/}
                                {/*/!*<Icon type="right" size="xs" style={{ color:"#333" }} />*!/*/}
                            {/*</Flex>*/}
                        {/*)*/}
                    {/*})*/}
                {/*}*/}
                {/*{*/}
                    {/*mansongGiftList!=undefined&&mansongGiftList!==''&&mansongGiftList.map((v,i,a)=>{*/}
                        {/*let name = "";*/}
                        {/*// let orderType = 1;*/}
                        {/*switch (v.activityType) {*/}
                            {/*case 10:*/}
                                {/*name = '满减';*/}
                                {/*break;*/}
                            {/*case 20:*/}
                                {/*name = "满免邮";*/}
                                {/*break;*/}
                            {/*case 30:*/}
                                {/*name = "满送";*/}
                                {/*break;*/}
                            {/*case 40:*/}
                                {/*name = "满折";*/}
                                {/*break;*/}
                            {/*case 50:*/}
                                {/*name = "团购";*/}
                                {/*break;*/}
                            {/*case 60:*/}
                                {/*name = "限时抢购";*/}
                                {/*break;*/}
                            {/*case 90:*/}
                                {/*name = "优惠券"*/}
                                {/*break;*/}
                        {/*}*/}

                        {/*return (*/}
                            {/*<Flex key={i} style={{margin:".1rem .1rem 0 .6rem"}} className="store_activity">*/}
                                {/*<div*/}
                                {/*style={{*/}
                                {/*padding:"0.05rem 0.1rem",*/}
                                {/*fontSize:"0.2rem",*/}
                                {/*color:"#ff0036",*/}
                                {/*backgroundColor:'#fbe9e9',*/}
                                {/*marginRight:'0.1rem'*/}
                                {/*}}>*/}
                                {/*{name}*/}
                                {/*</div>*/}
                                {/*<div style={{ fontSize:"0.22rem", color:"#333" }}>{v.name}</div>*/}
                                {/*/!*<Icon type="right" size="xs" style={{ color:"#333" }} />*!/*/}
                            {/*</Flex>*/}
                        {/*)*/}
                    {/*})*/}
                {/*}*/}
            </WingBlank>
                {
                    goodslist.map((goods, i,idx) => {
                        return (
                           <CartGoods
                               editStatus={editStatus}
                               goodsIndex={i}
                               idx={idx}
                               shopIndex={index}
                               dispatch={dispatch}
                               index={`${index}${i}`}
                               goods={goods}
                               key={i}>
                           </CartGoods>
                        );
                    })
                }

        </List>

        <Modal
          popup
          visible={vsible}
          animationType="slide-up"
          maskClosable={true}
          onClose={() => { this.setState({ vsible: false }); }}
          closable={true}
          title="优惠卷"
        >
            <div  >
                {
                    couponList.length > 0 ? <div style={{ height:"8rem" }}>
                        <CanChangeScroll
                        style={{ height:'100%', backgroundColor:"#e7e7e7" }}
                        wrapperId='CanChangeScrollCartWraperId'
                        targetId='CanChangeScrollCartTargetId'
                         >
                        <div style={{ padding:"0rem 0.2rem" }}>
                            {
                                couponList.map((v,i,a)=>{
                                    return <CouponItem dispatch={dispatch} storeId={ data.storeId} Item={v} key={i}></CouponItem>
                                })
                            }

                        </div>

                         </CanChangeScroll>
                        </div>
                        :
                        <div style={{height:"3rem"}}>
                            <Flex direction="column" justify="center" style={{ marginTop:'1rem' }}>
                                <Icon style={{ width:"50%", height:"auto" }}  type={noCoupon.id} />
                                <div>没有优惠卷了</div>
                            </Flex>
                        </div>
                }

            </div>
        </Modal>
      </div>
      // { goodslist!=''?<p style={{textAlign:'center',color:'#a5a5a5'}}>已经到底了</p>:<p style={{textAlign:'center',color:'#a5a5a5'}}>没有加入宝贝</p>}

  );
  }
}

export default CartShop;
